// Author  : Morbid
// Time    : 2022/04/30 20:31
// FileName: Main_905.java
// Software: IntelliJ IDEA

package LeetCode;

import java.util.Arrays;

public class Main_905 {
    //905. 按奇偶排序数组
    static int[] sortArrayByParity(int[] nums) {
        for (int i = 0, j = 0; i < nums.length && j < nums.length; j++) {
            while (i < nums.length && nums[i] % 2 == 0)
                i++;
            if (j > i && nums[j] % 2 == 0) {
                int tmp = nums[i];
                nums[i] = nums[j];
                nums[j] = tmp;
            }
        }
        return nums;
    }

    public static void main(String[] args) {
        int[] x = {0,5,9,8,4,3};
        System.out.println(Arrays.toString(sortArrayByParity(x)));
    }

}
